
#include <functional>
using namespace std;

#ifndef TIMER_HPP
#define TIMER_HPP

namespace tulun
{
    class Timer
    {
    public:
        using TimerCallback = std::function<void(void)>;

    private:
        int m_timerId;
        TimerCallback m_callback;
        int tag;                        // 1 一次运行，2 周期运行
        bool settimer(size_t interval); // 0
    public:
        Timer();
        ~Timer();
        Timer(const Timer &) = delete;
        Timer &operator=(const Timer &) = delete;
        Timer(Timer &&it) : m_timerId(it.m_timerId), m_callback(it.m_callback)
        {
            m_timerId = -1;
            m_callback = nullptr;
        }
        Timer &operator=(Timer &&it)
        {
            if (this != &it)
            {
                m_timerId = it.m_timerId;
                m_callback = it.m_callback;
                it.m_timerId = -1;
                it.m_callback = nullptr;
            }
            return *this;
        }
        bool init();
        bool set_timer(const TimerCallback &cb, size_t interval);
        bool resete_timer(size_t interval);
        void handle_event();
        size_t get_TimerId() const;
        bool close_timer();
    };
} // namespace tulun

#endif